package com.wc.alorithm_blue_bridge._前缀和与差分.Q3694;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;

/**
 * @Author congege
 * @Description
 * 肖恩的投球游戏加强版
 * https://www.lanqiao.cn/problems/3694/learning/?page=1&first_category_id=1
 *
 * 思路是：b[i][j] = (a[i][j] - a[i][j-1]) - (a[i-1][j] - a[i-1][j-1])
 * b[i][j] 变化影响的是从(1,1)到(i,j)的变化
 * @Date Created in 2023/11/23-17:13
 */
public class Main {
    static void insert(int x1,int y1,int x2,int y2,long c,long[][] b){
        b[x1][y1] += c;
        b[x1][y2 + 1] -= c;
        b[x2 + 1][y1] -= c;
        b[x2 + 1][y2 + 1] += c;
    }
    public static void main(String[] args) {
        Input scan = new Input();
        int n = scan.nextInt();
        int m = scan.nextInt();
        int q = scan.nextInt();
        long[][] a = new long[n + 2][m + 2];
        long[][] b = new long[n + 2][m + 2];
        for(int i = 1; i <=n; i++){
            for(int j = 1;j <=m; j++){
                a[i][j] = scan.nextInt();
                insert(i,j,i,j,a[i][j],b);
            }
        }

        while(q-- > 0){
            int x1 = scan.nextInt();
            int y1 = scan.nextInt();
            int x2 = scan.nextInt();
            int y2 = scan.nextInt();
            int c = scan.nextInt();
            insert(x1,y1,x2,y2,c,b);
        }

        StringBuffer ans = new StringBuffer();
        for(int i = 1; i <=n; i++){
            for(int j = 1;j <=m; j++){
                a[i][j] = a[i][j - 1] + a[i-1][j] - a[i-1][j-1] + b[i][j];
                ans.append(a[i][j]);
                ans.append(' ');
            }
            ans.append('\n');
        }
        System.out.println(ans);
        // scan.close();
    }

    static class Input{
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));

        public int nextInt(){
            try{
                in.nextToken();
            }catch(Exception e){
                return -1;
            }
            return (int) in.nval;
        }
    }
}
